package com.jz.community.modulemine.packet.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.flyco.tablayout.SlidingTabLayout;
import com.gyf.barlibrary.ImmersionBar;
import com.jz.community.basecomm.base.BaseMvpActivity;
import com.jz.community.basecomm.base.BaseX5WebActivity;
import com.jz.community.basecomm.constant.HtmlConstant;
import com.jz.community.basecomm.mvp.BaseMvpPresenter;
import com.jz.community.commview.commPagerAdapter.CommonViewPagerAdapter;
import com.jz.community.modulemine.R;
import com.jz.community.modulemine.R2;
import com.jz.community.modulemine.packet.ui.fragment.RedPacketFragment;

import butterknife.BindView;
import butterknife.OnClick;

public class RedPacketActivity extends BaseMvpActivity{

    @BindView(R2.id.red_packet_back)
    ImageView redPacketBack;
    @BindView(R2.id.red_packet_title)
    TextView redPacketTitle;
    @BindView(R2.id.red_packet_explain)
    ImageView redPacketExplain;
    @BindView(R2.id.red_packet_toolbar)
    Toolbar redPacketToolbar;
    @BindView(R2.id.red_packet_tab)
    SlidingTabLayout redPacketTab;
    @BindView(R2.id.red_packet_vp)
    ViewPager redPacketVp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected int getContentView() {
        return R.layout.module_mine_activity_red_packet;
    }

    @Override
    protected BaseMvpPresenter createPresenter() {
        return null;
    }


    @Override
    protected void initView() {
        super.initView();
        ImmersionBar.with(this)
                .titleBar(redPacketToolbar)
                .statusBarDarkFont(true, 0.2f)
                .init();

        redPacketTitle.setText("我的红包");
    }


    @Override
    protected void initDatas() {
        super.initDatas();
        initViewPager();

    }


    private void initViewPager() {
        String[] titles = {
                "可使用",
                "已失效"};

        CommonViewPagerAdapter viewPagerAdapter = new CommonViewPagerAdapter(getSupportFragmentManager());

        // 可使用
        RedPacketFragment firstFragment = RedPacketFragment.newInstance(0);
        viewPagerAdapter.addFragment(firstFragment);
        // 已失效
        RedPacketFragment secondFragment = RedPacketFragment.newInstance(1);
        viewPagerAdapter.addFragment(secondFragment);

        redPacketVp.setOffscreenPageLimit(2);
        redPacketVp.setAdapter(viewPagerAdapter);

        redPacketTab.setViewPager(redPacketVp, titles);
    }


    @OnClick(R2.id.red_packet_back)
    public void backClick(View view) {
        finish();
    }

    @OnClick(R2.id.red_packet_explain)
    public void explainClick(View view) {
        Intent mIntent = new Intent(mActivity, BaseX5WebActivity.class);
        mIntent.putExtra("url", HtmlConstant.PACKET_HTML_URL);
        mIntent.putExtra("title", "红包规则");
        startActivity(mIntent);
    }

}
